local Attributes = class("Attributes")
local attribute = require("config.attribute")
local AttributeConst = require("const.AttributeConst")

function Attributes:ctor()
    self._attrs = {}
    self._fakeAttr = {}
    self:_init()
end

function Attributes:_init()
    local len = attribute.length()
    for i = 1, len do
        local cfg = attribute.indexOf(i)
        local attrId = cfg.id
        if AttributeConst.INIT_MAP[attrId] then
            self._attrs[AttributeConst.INIT_MAP[attrId]] = 0
            self._attrs[attrId] = 0
        else
            self._attrs[attrId] = 0
        end
    end
end

function Attributes:setPureAttr(attrs)
    for attrId, value in pairs(attrs) do
        if AttributeConst.INIT_MAP[attrId] then
            self._attrs[AttributeConst.INIT_MAP[attrId]] = value
            self._attrs[attrId] = value
        else
            self._attrs[attrId] = value
        end
    end
end

function Attributes:getAttrValue(id)
    local attrValue1 = self._attrs[id] or 0
    local attrValue2 = self._fakeAttr[id] or 0
    local retValue = attrValue1 + attrValue2
    retValue = retValue < 0 and 0 or retValue
    return retValue
end

function Attributes:getBaseAttrValue(id)
    return self._attrs[id] or 0
end

function Attributes:setAttrValue(id, value)
    if value < 0 then
        self._attrs[id] = 0
    else
        self._attrs[id] = value
    end
end

function Attributes:setContent(attrs)
    self._attrs = attrs
end

function Attributes:getContent()
    return self._attrs
end

function Attributes:getFakeContent()
    return self._fakeAttr
end

function Attributes:getFakeAttrValue(id)
    return self._fakeAttr[id] or 0
end

function Attributes:setFakeAttrValue(id, value)
    if id == AttributeConst.BLOOD then -- 血量不可fake
        return
    end
    self._fakeAttr[id] = value
end

return Attributes
